﻿using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Windows.Controls;
using XYAC.Framework.MonitorTireMaterialManual.Extensions;
using XYAC.Framework.MonitorTireMaterialManual.ViewModels;
using static System.Net.Mime.MediaTypeNames;

namespace XYAC.Framework.MonitorTireMaterialManual.Views
{
    /// <summary>
    /// SystemConfigView.xaml 的交互逻辑
    /// </summary>
    public partial class SystemConfigView : UserControl
    {
        SystemConfigViewModel _viewmodel;
        public SystemConfigView(IOptionsMonitor<AppConfig> options, 
            ILogger<SystemConfigView> logger, 
            SystemConfigViewModel viewmodel)
        {
            this.AppConfig = options;
            _viewmodel=viewmodel;
            this.DataContext = viewmodel;
            this.Logger = logger;
            InitializeComponent();

            this.cmbDeviceType.SelectedItem = viewmodel.CurrentItem(viewmodel.MachineType);
            this.txtPasswork.Password = viewmodel.OraclePwd;
        }

        public IOptionsMonitor<AppConfig> AppConfig { get; }
        public ILogger<SystemConfigView> Logger { get; }

        private void cmbDeviceType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                if (e.AddedItems[0] is Item cbi)
                {
                    _viewmodel.MachineType = cbi.Value;
                }
            }
        }

        private void txtPasswork_PasswordChanged(object sender, System.Windows.RoutedEventArgs e)
        {
            _viewmodel.OraclePwd= this.txtPasswork.Password;
        }
    }
}
